using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using Banshee.Base;
using Banshee.Sources;
using System.ComponentModel;
using System.Windows.Forms;

namespace Banshee
{
    public class TrackSource
    {
        public TrackSource()
        {

        }
        protected SortableBindingList<TrackInfo> _tracks = new SortableBindingList<TrackInfo>();

        public SortableBindingList<TrackInfo> Tracks
        {
            get { return _tracks; }
            set { _tracks = value; }
        }
        TimeSpan totalDuration;

        public TimeSpan TotalDuration
        {
            get { return totalDuration; }
            set { totalDuration = value; }
        }
        public void Clear()
        {
            _tracks.Clear();
        }
        void AddTrack(TrackInfo track)
        {
            _tracks.Add(track);
        }
        public void Reload()
        {
            Clear();
            totalDuration = new TimeSpan(0);
            foreach (TrackInfo track in SourceManager.ActiveSource.Tracks)
            {
                //AddTrack(track);
                
                _tracks.Add(track);
                totalDuration.Add(track.Duration);
            }

        }
    }
    public class SortableBindingList<T> : BindingList<T>
    {
        protected override int FindCore(
          PropertyDescriptor property, object key)
        {

            // Specify search columns
            if (property == null) return -1;

            // Get list to search
            List<T> items = this.Items as List<T>;

            // Traverse list for value
            foreach (T item in items)
            {

                // Test column search value
                string value = (string)property.GetValue(item);

                // If value is the search value, return the 
                // index of the data item
                if ((string)key == value) return IndexOf(item);
            }
            return -1;
        }
    }
}
